package com.gxa.controller;

import com.gxa.pojo.Tenant;
import com.gxa.service.TenantService;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Tenant)表控制层
 *
 * @author makejava
 * @since 2022-09-01 12:39:08
 */
@Api(tags = "租户管理控制器")
@RestController
@RequestMapping("tenant")
public class TenantController {
    /**
     * 服务对象
     */
    @Resource
    private TenantService tenantService;

    /**
     * 分页查询
     *
     * @param tenant 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查找数据并分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantLicense", value = "营业执照", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantLeader", value = "负责人", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantScale", value = "规模", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIsMarket", value = "是否上市", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantLogo", value = "企业logo", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantTel", value = "联系方式", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredFunds", value = "注册资金", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredTime", value = "注册时间", dataType = "java.util.Date", paramType = "body"),
            @ApiImplicitParam(name = "tenantValuation", value = "企业估值", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantBuilding", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRoomId", value = "房间号", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantName", value = "租户名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantCode", value = "社会信用代码", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIndustry", value = "所属行业", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIs", value = "是否高新", dataType = "java.lang.Integer", paramType = "body"),
    })
    @PostMapping("/queryByPage")
    public ResponseData queryByPage(Tenant tenant, @ApiParam(value = "页码") int page, @ApiParam(value = "每页多少条") int size) {
        ResponseData responseData = new ResponseData();
        responseData.setData(this.tenantService.queryByPage(tenant, page, size));
        return responseData;
    }

//    /**
//     * 通过主键查询单条数据
//     *
//     * @param tenant 主键
//     * @return 单条数据
//     */
//    @PostMapping("/query")
//    public ResponseData query(Tenant tenant) {
//        ResponseData responseData = new ResponseData();
//        responseData.setData(this.tenantService.query(tenant));
//        return responseData;
//    }

    /**
     * 新增数据
     * @param tenant 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantLicense", value = "营业执照", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantLeader", value = "负责人", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantScale", value = "规模", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIsMarket", value = "是否上市", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantLogo", value = "企业logo", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantTel", value = "联系方式", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredFunds", value = "注册资金", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredTime", value = "注册时间", dataType = "java.util.Date", paramType = "body"),
            @ApiImplicitParam(name = "tenantValuation", value = "企业估值", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantBuilding", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRoomId", value = "房间号", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantName", value = "租户名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantCode", value = "社会信用代码", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIndustry", value = "所属行业", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIs", value = "是否高新", dataType = "java.lang.Integer", paramType = "body"),
    })
    @PostMapping("/add")
    public ResponseData add(@RequestBody Tenant tenant) {
        ResponseData responseData = new ResponseData();
        if (this.tenantService.insert(tenant) > 0) {
            responseData.setCode(200);
            responseData.setMsg("success");
        } else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

    /**
     * 编辑数据
     *
     * @param tenant 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantLicense", value = "营业执照", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantLeader", value = "负责人", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantScale", value = "规模", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIsMarket", value = "是否上市", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantLogo", value = "企业logo", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantTel", value = "联系方式", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredFunds", value = "注册资金", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredTime", value = "注册时间", dataType = "java.util.Date", paramType = "body"),
            @ApiImplicitParam(name = "tenantValuation", value = "企业估值", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantBuilding", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRoomId", value = "房间号", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantName", value = "租户名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantCode", value = "社会信用代码", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIndustry", value = "所属行业", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIs", value = "是否高新", dataType = "java.lang.Integer", paramType = "body"),
    })
    @PutMapping("/change")
    public ResponseData edit(Tenant tenant) {
        ResponseData responseData = new ResponseData();
        Tenant update = this.tenantService.update(tenant);
        if (update.equals(null)){
            responseData.setCode(404);
            responseData.setMsg("fail");}else {
            responseData.setCode(200);
            responseData.setData(update);
        }
        return responseData;
    }

    /**
     * 删除数据
     *
     * @param tenant 筛选条件
     * @return 删除是否成功
     */
    @ApiOperation(value = "根据条件删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantLicense", value = "营业执照", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantLeader", value = "负责人", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantScale", value = "规模", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIsMarket", value = "是否上市", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantLogo", value = "企业logo", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantTel", value = "联系方式", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredFunds", value = "注册资金", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantRegisteredTime", value = "注册时间", dataType = "java.util.Date", paramType = "body"),
            @ApiImplicitParam(name = "tenantValuation", value = "企业估值", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantBuilding", value = "所属楼宇", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantRoomId", value = "房间号", dataType = "java.lang.Integer", paramType = "body"),
            @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantName", value = "租户名称", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantCode", value = "社会信用代码", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIndustry", value = "所属行业", dataType = "java.lang.String", paramType = "body"),
            @ApiImplicitParam(name = "tenantIs", value = "是否高新", dataType = "java.lang.Integer", paramType = "body"),
    })
    @DeleteMapping("/delete")
    public ResponseData deleteById(Tenant tenant) {
        ResponseData responseData = new ResponseData();
        if (this.tenantService.deleteById(tenant)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }

}

